package cn.tedu.csmall.product.controller;

import cn.tedu.csmall.product.pojo.dto.CategoryAddNewDTO;
import cn.tedu.csmall.product.pojo.vo.CategoryListItemVO;
import cn.tedu.csmall.product.service.ICategoryService;
import cn.tedu.csmall.product.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@Api(tags = "01.类别管理模块")
@Slf4j
@RestController
@RequestMapping("/categories")
public class CategoryController {
    @Autowired
    private ICategoryService service;

    public CategoryController(){
        log.debug("创建控制器对象：CategoryController");
    }

    @ApiOperation("添加类别")
    @ApiOperationSupport(order = 100)
    @PostMapping("/add-new")
    public JsonResult addNew(@Valid CategoryAddNewDTO categoryAddNewDTO){
        service.addNew(categoryAddNewDTO);
        return JsonResult.ok();
    }

    @ApiOperation("删除类别")
    @ApiOperationSupport(order = 200)
    @ApiImplicitParam(name = "id", value = "类别id", required = true, dataType = "long")
    @PostMapping("/{id:[0-9]+}/delete")
    public JsonResult delete(@PathVariable Long id){
        log.debug("开始处理【根据id删除类别】的请求，参数：{}", id);
        service.deleteById(id);
        return JsonResult.ok();
    }

    @ApiOperation("启用类别")
    @ApiOperationSupport(order = 310)
    @ApiImplicitParam(name = "id", value = "类别id", required = true, dataType = "long")
    @PostMapping("/{id:[0-9]+}/enable")
    public JsonResult setEnable(@PathVariable Long id){
        log.debug("开始处理【启动类别】的请求，参数：{}",id);
        service.setEnable(id);
        return JsonResult.ok();
    }

    @ApiOperation("禁用类别")
    @ApiOperationSupport(order = 320)
    @ApiImplicitParam(name = "id", value = "类别id", required = true, dataType = "long")
    @PostMapping("/{id:[0-9]+}/disable")
    public JsonResult setDisable(@PathVariable Long id){
        log.debug("开始处理【禁用类别】的请求，参数：{}",id);
        service.setDisable(id);
        return JsonResult.ok();
    }

    @ApiOperation("显示类别")
    @ApiOperationSupport(order = 330)
    @ApiImplicitParam(name = "id", value = "类别id", required = true, dataType = "long")
    @PostMapping("/{id:[0-9]+}/isDisplay")
    public JsonResult setIsDisplay(@PathVariable Long id){
        log.debug("开始处理【显示类别】的请求，参数：{}",id);
        service.setIsDisplay(id);
        return JsonResult.ok();
    }

    @ApiOperation("隐藏类别")
    @ApiOperationSupport(order = 340)
    @ApiImplicitParam(name = "id", value = "类别id", required = true, dataType = "long")
    @PostMapping("/{id:[0-9]+}/notDisplay")
    public JsonResult setNotDisplay(@PathVariable Long id){
        log.debug("开始处理【隐藏类别】的请求，参数：{}",id);
        service.setNotDisplay(id);
        return JsonResult.ok();
    }

    @ApiOperation("修改类别详情")
    @ApiOperationSupport(order = 350)
    @PostMapping("/update")
    public void update(){

    }

    @ApiOperation("根据id查询类别详情")
    @ApiOperationSupport(order = 410)
    @PostMapping("/get")
    public void getStandardById(){

    }

    @ApiOperation("查询类别列表")
    @ApiOperationSupport(order = 420)
    @GetMapping("")
    public JsonResult list(){
        log.debug("开始处理【查询类别列表】的请求，参数：无");
        List<CategoryListItemVO> list = service.list();
        return JsonResult.ok(list);
    }

    @ApiOperation("根据父级类别id查询子级类别")
    @ApiOperationSupport(order = 430)
    @ApiImplicitParam(name = "parentId", value = "父级类别id", required = true, dataType = "long")
    @GetMapping("/list-by-parent")
    public JsonResult listByParentId(Long parentId){
        log.debug("开始处理【根据父级类别id查询子级类别】的请求，参数：{}", parentId);
        List<CategoryListItemVO> list = service.listByParentId(parentId);
        return JsonResult.ok(list);
    }

}
